home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / CIncludesTool 1.0 / modified version / source files / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-19  |  2.7 KB  |  148 lines  |  [TEXT/MPS ]

  1. // main.c
  2. //
  3. // part of CIncludesCode MPW tool
  4. // original version by John Jeppson
  5. // this tool should normally be called by CIncludesTool MPW Script
  6.  
  7. #include <PLStringFuncs.h>
  8. #include <StdIO.h>
  9. #include <StdLib.h>
  10. #include <String.h>
  11. #include "CIncludesCode.h"
  12.  
  13. Handle database = 0;
  14. long numFiles;
  15. dataHeaderType dataHeader;
  16. Str255 dataFilename;
  17.  
  18. void CreateDataFileName(void)
  19. // generate the correct datafile name based on the compiler environment variable
  20.  
  21. {
  22. char *pszCompiler = getenv("CIncludesCompiler");
  23. if (strcmp(pszCompiler,"MetrowerksC++") == 0)
  24.     {
  25.     (void) PLstrcpy(dataFilename,"\p:Preferences:Metrowerks CIncludesData");
  26.     }  // if stricmp()
  27. else
  28.     {
  29.     if (strcmp(pszCompiler,"SymantecC++") == 0)
  30.         {
  31.         (void) PLstrcpy(dataFilename,"\p:Preferences:Symantec CIncludesData");
  32.         }  // if stricmp()
  33.     else
  34.         {
  35.         (void) PLstrcpy(dataFilename,"\p:Preferences:Apple CIncludesData");
  36.         }  // else if stricmp()
  37.     }  // else if stricmp()
  38. }  // CreateDataFileName()
  39.  
  40. short validateArguments(int argc,char *argv[])
  41. // terminates tool if bad parameters
  42.  
  43. switch(argc)
  44.     {
  45.     case 1:
  46.     case 2:
  47.         {
  48.         exit( 1 );
  49.         break;
  50.         }  // case 1,2
  51.     case 3:
  52.         {
  53.         if (strcmp(argv[1],"-v") == 0)
  54.             {
  55.             return 2;
  56.             }  // if strcpm()
  57.         if (strcmp(argv[1],"-f") == 0)
  58.             {
  59.             return 3;
  60.             }  // if strcpm()
  61.         if (strcmp(argv[1],"-i") == 0)
  62.             {
  63.             return 4;
  64.             }  // if strcpm()
  65.         if (strcmp(argv[1],"-d") == 0)  // Daniel Grassi
  66.             {
  67.             return 5;
  68.             }  // if strcpm()
  69.         exit( 1 );
  70.         break;
  71.         }  // case 3    
  72.     default:
  73.         {
  74.         if (strcmp(argv[1],"-m") == 0)
  75.             {
  76.             return 1;
  77.             }  // if strcmp()
  78.         exit( 1 );
  79.         break;
  80.         }  // default
  81.     }  // switch argc
  82. }  // validateArguments()
  83.  
  84. int main(int argc,char *argv[])
  85. {
  86. char s[64];
  87. long filePosition;
  88.  
  89. CreateDataFileName();
  90. switch(validateArguments(argc,argv))
  91.     {
  92.     case 1:  // -m
  93.         {
  94.         return (createDataBase(argc,argv));
  95.         break;
  96.         }  // case 1
  97.     case 2:  // -v
  98.         {
  99.         return (validate(argv[2]));
  100.         break;
  101.         }  // case 2
  102.     case 3:  // -f
  103.         {
  104.         if (!loadDatabase())
  105.             {
  106.             return(3);
  107.             }  // if !loadDatabase()
  108.         if (locateIdentifier(s,&filePosition,argv[2]))
  109.             {
  110.             (void) printf("#include <%s>\n", s );
  111.             }  // if locateIdentifier()
  112.         else
  113.             {
  114.             return(4);
  115.             }  // else if locateIdentifier
  116.         break;
  117.         }  // case 3
  118.     case 4:  // -i
  119.         {
  120.         if (!loadDatabase())
  121.             {
  122.             return(3);
  123.             }  // if !loadDatabase()
  124.         return (reformat(argv[2]));
  125.         break;
  126.         }  // case 4
  127.     case 5:  // -d (Daniel Grassi)
  128.         {
  129.         if (!loadDatabase())
  130.             {
  131.             return(3);
  132.             }  // if !loadDatabase()
  133.         if (locateIdentifier(s,&filePosition,argv[2]))
  134.             {
  135.             printf("\"%s\"  %d",s,filePosition);
  136.             }  // if locateIdentifier()
  137.         else
  138.             {
  139.             return(4);
  140.             }  // else if locateIdentifier()
  141.         break;
  142.         }  // case 5
  143.     }  // switch validateArguments()
  144. return 0;
  145. }  // main()
  146.  
  147. // end of main.c